﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using Microsoft.Win32;
using System.IO;

namespace WpfTestApplication
{
    /// <summary>
    /// Interaction logic for OpenFileDialogTestWindow.xaml
    /// </summary>
    public partial class OpenFileDialogTestWindow : Window
    {
        public OpenFileDialogTestWindow()
        {
            InitializeComponent();
        }

        private void btnOpenFile_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog { Multiselect = false };
            if (ofd.ShowDialog(this).Value)
            {
                string filename = ofd.FileName;
                this.txtOpenFile.Text = File.ReadAllText(filename);
            }
        }

        private void btnOpenFiles_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog { Multiselect = true };
            if (ofd.ShowDialog(this).Value)
            {
                string[] filenames = ofd.FileNames;
                StringBuilder stringBuilder = new StringBuilder();
                foreach (string s in filenames)
                {
                    stringBuilder.Append(File.ReadAllText(s));
                }
                this.txtOpenFiles.Text = stringBuilder.ToString();
            }
        }

        private void btnOpenFileTitle_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog { Multiselect = false, Title = "Open my file" };
            if (ofd.ShowDialog(this).Value)
            {
                string filename = ofd.FileName;
                this.txtOpenFile.Text = File.ReadAllText(filename);
            }
        }
    }
}
